const { ccclass, property } = cc._decorator;

@ccclass
export default class MusicButton extends cc.Component {
    @property(cc.Sprite)
    SpriteButton: cc.Sprite = null;
    @property(cc.SpriteFrame)
    SpriteFrameOpen: cc.SpriteFrame = null;
    @property(cc.SpriteFrame)
    SpriteFrameClose: cc.SpriteFrame = null;

    private isOpen: boolean = false;
    private mCallBack: any = null;

    public init(is: boolean, endCb: any = null) {
        this.isOpen = is;
        this.mCallBack = endCb;
        this.refreshUi();
    }

    public refreshUi(): void {
        if (this.isOpen) {
            this.SpriteButton.spriteFrame = this.SpriteFrameOpen;
        }
        else {
            this.SpriteButton.spriteFrame = this.SpriteFrameClose;
        }
    }

    public onClick(): void {
        this.isOpen = !this.isOpen;
        this.refreshUi();
        if (this.mCallBack) {
            this.mCallBack(this.isOpen);
        }
    }
}
